/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.ce.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author Jarik
 */
@Entity
@Table(name = "query")
@NamedQueries({
    @NamedQuery(name = "Query.findAll", query = "SELECT q FROM Query q"),
    @NamedQuery(name = "Query.findById", query = "SELECT q FROM Query q WHERE q.id = :id"),
    @NamedQuery(name = "Query.findByOpenDate", query = "SELECT q FROM Query q WHERE q.openDate = :openDate"),
    @NamedQuery(name = "Query.findByFinishDate", query = "SELECT q FROM Query q WHERE q.finishDate = :finishDate"),
    @NamedQuery(name = "Query.findByAmount", query = "SELECT q FROM Query q WHERE q.amount = :amount"),
    @NamedQuery(name = "Query.findByRateFrom", query = "SELECT q FROM Query q WHERE q.rateFrom = :rateFrom"),
    @NamedQuery(name = "Query.findByRateTo", query = "SELECT q FROM Query q WHERE q.rateTo = :rateTo"),
    @NamedQuery(name = "Query.findByStatus", query = "SELECT q FROM Query q WHERE q.status = :status"),
    @NamedQuery(name = "Query.findByOppositeStatus", query = "SELECT q FROM Query q WHERE q.status <> :status"),
    @NamedQuery(name = "Query.findByClosedRate", query = "SELECT q FROM Query q WHERE q.closedRate = :closedRate"),
    @NamedQuery(name = "Query.findByClosedDate", query = "SELECT q FROM Query q WHERE q.closedDate = :closedDate")})
public class Query implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "OpenDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date openDate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "FinishDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date finishDate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Amount")
    private Double amount;
    @Basic(optional = false)
    @NotNull
    @Column(name = "RateFrom")
    private Double rateFrom;
    @Basic(optional = false)
    @NotNull
    @Column(name = "RateTo")
    private Double rateTo;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "Status")
    private String status;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "ClosedRate")
    private Double closedRate;
    @Column(name = "ClosedDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date closedDate;
    @JoinColumn(name = "ExecutedByUser", referencedColumnName = "id")
    @ManyToOne
    private User executedByUser;
    @JoinColumn(name = "OpenByUser", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private User openByUser;
    @JoinColumn(name = "CurrencyTo", referencedColumnName = "ShortName")
    @ManyToOne(optional = false)
    private Currency currencyTo;
    @JoinColumn(name = "CurrencyFrom", referencedColumnName = "ShortName")
    @ManyToOne(optional = false)
    private Currency currencyFrom;

    public Query() {
    }

    public Query(Integer id) {
        this.id = id;
    }

    public Query(Integer id, Date openDate, Date finishDate, double amount, double rateFrom, double rateTo, String status) {
        this.id = id;
        this.openDate = openDate;
        this.finishDate = finishDate;
        this.amount = amount;
        this.rateFrom = rateFrom;
        this.rateTo = rateTo;
        this.status = status;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getOpenDate() {
        return openDate;
    }

    public void setOpenDate(Date openDate) {
        this.openDate = openDate;
    }

    public Date getFinishDate() {
        return finishDate;
    }

    public void setFinishDate(Date finishDate) {
        this.finishDate = finishDate;
    }

    public Double getAmount() {
        return amount;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public Double getRateFrom() {
        return rateFrom;
    }

    public void setRateFrom(Double rateFrom) {
        this.rateFrom = rateFrom;
    }

    public Double getRateTo() {
        return rateTo;
    }

    public void setRateTo(Double rateTo) {
        this.rateTo = rateTo;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Double getClosedRate() {
        return closedRate;
    }

    public void setClosedRate(Double closedRate) {
        this.closedRate = closedRate;
    }

    public Date getClosedDate() {
        return closedDate;
    }

    public void setClosedDate(Date closedDate) {
        this.closedDate = closedDate;
    }

    public User getExecutedByUser() {
        return executedByUser;
    }

    public void setExecutedByUser(User executedByUser) {
        this.executedByUser = executedByUser;
    }

    public User getOpenByUser() {
        return openByUser;
    }

    public void setOpenByUser(User openByUser) {
        this.openByUser = openByUser;
    }

    public Currency getCurrencyTo() {
        return currencyTo;
    }

    public void setCurrencyTo(Currency currencyTo) {
        this.currencyTo = currencyTo;
    }

    public Currency getCurrencyFrom() {
        return currencyFrom;
    }

    public void setCurrencyFrom(Currency currencyFrom) {
        this.currencyFrom = currencyFrom;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Query)) {
            return false;
        }
        Query other = (Query) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bionic.ce.entities.Query[ id=" + id + " ]";
    }
    
}
